package com.example.controller;

import com.example.pojo.dao.ChatDao;
import com.example.pojo.dao.ChatRecordsRepository;
import com.example.pojo.entity.Chat;
import com.example.pojo.entity.ChatRecords;
import com.example.service.ChatService;
import com.example.vo.Result;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用来获取该聊天中的历史记录
 * @author ..
 * @Date 2023/10/29 19:01
 */
@RestController
@RequestMapping("cANDm")
public class ChatAndMessageController {

    private static ChatService chatService;

    private static ChatDao chatDao;

    @Autowired
    private void cs(ChatService chatService){
        ChatAndMessageController.chatService=chatService;
    }

    @Autowired
    private void ct(ChatDao chatDao){
        ChatAndMessageController.chatDao=chatDao;
    }


    @Autowired
    private ChatRecordsRepository chatRecordsRepository;

    @PostMapping("chatMessageJS/{jrId}/{jsId}")
    public Result getMessages(@PathVariable("jrId")Integer jrId,@PathVariable("jsId")Integer jsId){
        Chat chat = chatService.findByJsJrID(jsId,jrId);
        List<ChatRecords> chatRecordsList = chatRecordsRepository.findByChatId(chat.getId());
        return new Result(200,"查询成功",chatRecordsList);
    }

    @PostMapping("chat/{jrId}")
    public Result getChat(@PathVariable("jrId")Integer jrId){
        List<Chat> chats = chatService.findByJrId(jrId);
        return new Result(200,"查询成功",chats);
    }

    @PostMapping("message/{jsId}")
    public Result getMessage(@PathVariable("jsId")Integer jsId){
        List<Chat> chats = chatService.findByJsId(jsId);
        return new Result(200,"查询成功",chats);
    }

    @PostMapping("JrAndJs/{jrId}/{jsId}")
    public Result jrAndjs(@PathVariable("jrId")Integer jrId,@PathVariable("jsId")Integer jsId){
        Chat chat = chatService.findByJsJrID(jsId,jrId);
        return new Result(200,"查询成功",chat);
    }


}
